#include<iostream>
#include<string>
using namespace std;

class Solution {
public:
    int minFlips(string s) {
        int n=s.size();
        string target="01";
        int cnt=0;
        for(int i=0;i<n;++i)
            cnt+=s[i]!=target[i%2];

        int ans=min(cnt,n-cnt);
        if(n%2==0) return ans;

        for(int i=0;i<n;++i)
        {
            cnt-=s[i]!=target[i%2];
            cnt+=s[i]!=target[(i+n)%2]; 
            ans=min(ans,min(cnt,n-cnt));
        }
        return ans;
    }
};